home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 November / Macworld Nov ’95.toast / Education / xModels 2D and 3D / Tutorial Examples / Tutorial 4. Transformations < prev    next >
Encoding:
Text File  |  1995-06-22  |  2.5 KB  |  68 lines  |  [TEXT/X_#9]

  1. ; Tutorial 4: Transformations
  2. ;
  3.         animate 30  ; this file defines a 30-frame animation
  4. ;
  5. ; Geometric transformations include the operations of
  6. ; rotation, scaling, and translation that were introduced
  7. ; in previous tutorials.  However, there is quite a bit
  8. ; more to say.
  9. ;
  10. ; First of all, the scale transformation can optionally take
  11. ; a second parameter, as in "scale 2,5".  The first parameter,
  12. ; 2, specifies a scaling factor in the horizontal direction, and
  13. ; the second parameter, 5, specifies a scaling factor in the
  14. ; vertical direction.  "Scale 2" is equivalent to "scale 2,2".
  15. ; For example:
  16.  
  17.         graysquare scale 2,5  ; a 2-by-5 RECTANGLE
  18.  
  19. ; Note that scaling a square by different factors in the
  20. ; horizontal and veritcal directions produces a rectangle.
  21. ; Applying the same transformation to a circle gives an ellipse.
  22. ;
  23. ; Besides the basic "translate" command, two other commands
  24. ; are provided for convenience: "xtranslate" and "ytranslate".
  25. ; "Xtranslate" does horizontal translation and "ytranslate" does
  26. ; vertical translation:
  27.  
  28.        circle scale 2,5 xtranslate 3
  29.            ; equivalent to:  circle scale 2,5 translate 3,0
  30.        blackcircle scale 5,2 ytranslate 5
  31.            ; equivalent to:  blackcircle scale 5,2 translate 0,5
  32.  
  33. ; (There are also "xscale" and "yscale" commands, which take
  34. ; one parameter and perform the obvious operations.)
  35. ;
  36. ; As for rotation, it is important to understand that "rotate"
  37. ; specifies a rotation about the point (0,0).  So, in
  38.  
  39.        line scale 5 ytranslate -8 rotate 0:180
  40.  
  41. ; the line rotates around the center of the window, not about is
  42. ; own center.  You can specify a different center of rotation
  43. ; like this:
  44.  
  45.        line scale 3 xtranslate -8 rotate 0:180 about -8,0
  46.  
  47. ; This line rotates about the point (-8,0), which happens
  48. ; to be its center.
  49. ;
  50. ; I have used examples of scaling and rotation in which the
  51. ; parameters were positive.  Negative numbers are also allowed.
  52. ; Scaling by a negative number implies a reflection. Rotation
  53. ; by a negative number implies a clockwise rotation, while a
  54. ; positive rotation is counterclockwise.
  55. ;
  56. ; xModels-2D supports two additional transformations: xskew
  57. ; and yskew.  For example:
  58.  
  59.         square scale 3
  60.            xskew 0:2  ; apply a varying "horizontal slant"
  61.            translate -6,6  ; move it so it can be seen easily
  62.  
  63.         blacksquare scale 3
  64.            yskew 0:2  ; apply a varying "vertical slant"
  65.            translate -6,-6  ; and move it
  66.  
  67. ; ("Xskew a" moves the point (x,y) to (x+ay,y), and "yskew b"
  68. ; moves the point (x,y) to (x,y+bx).)